import { defaultsVal } from '../config/defaulVal'
import { AjaxConfig } from '../request/ajax'
export default function setOption(option: Object): AjaxConfig {
    const data: AjaxConfig = {
        type: option.type || "get",
        baseURL: option.baseURL || defaultsVal.baseURL,
        url: option.url,
        headers: {
            ...defaultsVal.headers.common,
            ...option.headers
        },
        data: option.data,
        params: option.params,
        timeout: option.timeout || defaultsVal.timeout,
        transformRequest: option.transformRequest || defaultsVal.transformRequest,
        transformResponse: option.transformResponse || defaultsVal.transformResponse,
        withCredentials: option.withCredentials || defaultsVal.withCredentials
    }
    return data
}
